package com.example.calculate;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tv;
    private TextView inputTV;
    private StringBuffer inputSb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //历史纪录
        tv = (TextView) findViewById(R.id.TV);
        //当前输入
        inputTV = (TextView) findViewById(R.id.inputTV);
        inputTV.setTextSize(18);
        inputSb= new StringBuffer();
        //数字区按键
        Button zero = (Button) findViewById(R.id.zero);
        Button one = (Button) findViewById(R.id.one);
        Button two = (Button) findViewById(R.id.two);
        Button three = (Button) findViewById(R.id.three);
        Button four = (Button) findViewById(R.id.four);
        Button five = (Button) findViewById(R.id.five);
        Button six = (Button) findViewById(R.id.six);
        Button seven = (Button) findViewById(R.id.seven);
        Button eight = (Button) findViewById(R.id.eight);
        Button nine = (Button) findViewById(R.id.nine);
        //功能区按键
        Button mc = (Button) findViewById(R.id.mc);
        Button mPlus = (Button) findViewById(R.id.mPlus);
        Button mJian = (Button) findViewById(R.id.mJian);
        Button C = (Button) findViewById(R.id.C);
        Button cheng = (Button) findViewById(R.id.cheng);
        Button chu = (Button) findViewById(R.id.chu);
        Button mr = (Button) findViewById(R.id.mr);
        Button jia_and_jian = (Button) findViewById(R.id.jia_and_jian);
        Button jian = (Button) findViewById(R.id.jian);
        Button jia = (Button) findViewById(R.id.jia);
        Button  equal = (Button) findViewById(R.id.equal);
        Button spot = (Button) findViewById(R.id.spot);
        //点击事件监听器
        zero.setOnClickListener(this);
        one.setOnClickListener(this);
        two.setOnClickListener(this);
        three.setOnClickListener(this);
        four.setOnClickListener(this);
        five.setOnClickListener(this);
        six.setOnClickListener(this);
        seven.setOnClickListener(this);
        eight.setOnClickListener(this);
        nine.setOnClickListener(this);
        mc.setOnClickListener(this);
        mPlus.setOnClickListener(this);
        mJian.setOnClickListener(this);
        C.setOnClickListener(this);
        cheng.setOnClickListener(this);
        chu.setOnClickListener(this);
        mr.setOnClickListener(this);
        jia.setOnClickListener(this);
        jian.setOnClickListener(this);
        jia_and_jian.setOnClickListener(this);
        equal.setOnClickListener(this);
        spot.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.zero:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("0"));
                break;
            case R.id.one:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("1"));
                break;
            case R.id.two:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("2"));
                break;
            case R.id.three:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("3"));
                break;
            case R.id.four:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("4"));
                break;
            case R.id.five:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("5"));
                break;
            case R.id.six:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("6"));
                break;
            case R.id.seven:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("7"));
                break;
            case R.id.eight:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("8"));
                break;
            case R.id.nine:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("9"));
                break;
            case R.id.C:            //清除输入框和历史记录所有内容
                inputSb.append(tv.getText());

                break;
            case R.id.cheng:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("*"));
                break;
            case R.id.chu:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("/"));
                break;
            case R.id.mc:               //清除输入框
                inputSb.append(tv.getText());

                break;
            case R.id.mPlus:
                break;
            case R.id.mJian:
                break;

            case R.id.mr:
                break;
            case R.id.jia:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("+"));
                break;
            case R.id.jian:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("-"));
                break;
            case R.id.jia_and_jian:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("+/-"));
                break;

            case R.id.equal:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("="));
                break;
            case R.id.spot:
                inputSb.append(tv.getText());
                inputTV.setText(inputSb.append("."));
                break;
        }


    }
}
